#include "app_audio.h"
#include "usart.h"
#include "timer.h"

u8 wait_audio = 0;
static void audio_wait_Handler(void)
{
  wait_audio = 0;
}

void audio_play(u8 id,u8 timer)
{
  u8 data[6] = {0xAA, 0x07, 0x02, 0x00, 0x00, 0x00};
  data[4] = id;
  data[5] = 0xB3 + id;
  if(wait_audio == 0)
  {
    wait_audio = 1;
    uart2_transData(data,6);
    timer_start(TIMER_AUDIO_WAIT_HANDLE, TIMER_S*timer, audio_wait_Handler);
  }
}


//声音大小 0-30
void audio_voice(u8 id) 
{
  u8 data[5] = {0xAA, 0x13, 0x01};
  data[3] = id;
  data[4] = 0xBE + id;
  uart2_transData(data,5);  
}

//声音播放测试 声音大小 0-30
void audio_test(u8 id) 
{
  audio_voice(id);  //音量设置
    HAL_Delay(100);
  audio_play(1,3);    //1欢迎使用老人智慧监测系统
    HAL_Delay(5000);
  audio_play(2,3);    //2主人您好，系统启动完成，我将持续为您监测身体安康
    HAL_Delay(5000);
  audio_play(3,3);    //3系统监测到您身体温度过高，请到附近医院检查
    HAL_Delay(5000);
  audio_play(4,3);    //4心率异常，请注意调整身体状态
    HAL_Delay(5000);
  audio_play(5,3);    //5血氧浓度偏低，请保持正常呼吸
    HAL_Delay(5000);
  audio_play(6,3);    //6跌倒警报，需要帮助
}
